<?php
/**
 * Created by PhpStorm.
 * User: Kevin
 * Date: 2018/9/10
 * Time: 18:22
 */
namespace app\admin\model;
use think\Db;
use think\Model;
class OrderModel extends Model
{
    protected $name = 'order';

    public function getOrderData($map,$od,$nowpage,$limits)
    {
        return $this->alias ('o')
            ->join('u_user u','o.order_userid = u.user_id','left')
            ->where($map)
            ->field('order_id,order_number,order_num,order_user_pay,order_remark,order_type,order_status,order_time,order_paytime,user_id,user_username,order_in_out')
            ->order($od)
            ->page($nowpage,$limits)
            ->select();
    }

    public function getAllCount($map)
    {
        return $this->alias ('o')
            ->join('u_user u','o.order_userid = u.user_id','left')
            ->where($map)
            ->count();
    }

    public function getOrderDetail($id){
        $data =  $this->alias ('o')
            ->join('shops s','s.s_id = o.order_shopid','left')
            ->where('order_id',$id)
            ->field('order_id,order_number,order_num,order_address_sex,order_address,order_address_phone,order_address_name,order_user_pay,order_remark,order_type,order_status,order_back_transaction_id,order_time,order_paytime,s_name')
            ->find();
        if(!empty($data)){
            $info = Db::name('order_info')
                ->where('oi_order_id',$id)
                ->field('oi_good_name,oi_num,oi_price_before,oi_price_now,oi_price_kill,oi_good_thumb')
                ->select();
        }
        $data['product'] = $info;
        return $data;
    }
}